﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace DAL
{
    public class UserDAL
    {

        public static User FindUserInfo(User user)
        {
            //将接受到的用户信息拼接成SQL语句传递给DAL(数据访问)层进行验证
            string sql = "SELECT userPower FROM UserTable WHERE userName='{0}' and userPassWord='{1}'";
            sql = string.Format(sql, user.Name, user.PassWord);//拼接查询语句
            //调用SQLHelper类的方法，返回一个读取器
            SqlDataReader sqlDataReader =  SQLHelper.GetSqlDataReader(sql);
            //判断是否查询到数据
            if (sqlDataReader.Read())
            {
                //对权限进行赋值
                user.UserPower = sqlDataReader["userPower"].ToString();
                return user;
            }
            else
            {
                return null;                
            }

        }

    }
}
